<?php
require_once(dirname(dirname(__FILE__)).'/helper.php');

global $header;
global $footer;
global $control;
global $message;
global $dictionary, $terms, $pageNav, $category, $count, $source_all_abbrs, $isEditor;

global $featureManager;
$header['title'] = $dictionary['title'];
if($isEditor) $header['head'] = '
<link rel="stylesheet" type="text/css" href="'.RESOURCE_BASE.'jqueryui/dialog/jquery-ui-1.7.2.dialog.css" />
<script type="text/javascript" src="'.RESOURCE_BASE.'jqueryui/jquery-ui-1.7.2.drag.drop.sort.min.js"></script>
<script type="text/javascript" src="'.RESOURCE_BASE.'jqueryui/dialog/jquery-ui-1.7.2.dialog.min.js"></script>
<script type="text/javascript" src="'.RESOURCE_BASE.'dictionary/base.js"></script>
';
$header['intro'] = '<em class="title">'.$dictionary['title'].'</em>';
$header['hasToolBar'] = TRUE;
$featureManager->apply("com.yizin.platform.site.header", $header);
$featureManager->apply("com.yizin.platform.site.footer", $footer);
$featureManager->apply("com.yizin.platform.site.control", $control);

global $iscontrol;
$iscontrol = $isEditor;

?>
<?= $header['html']?>
<div class="container-L">
	<?=$control['html']?>
</div>
<div class="container-R">
	<?=Utils::showMessage($message)?>
	<?=Utils::loadSegment(dirname(__FILE__)."/segments/_s_dictionary_toolbar_.php")?>
	<?=Utils::loadSegment(dirname(__FILE__)."/segments/_s_dictionary_search_.php")?>
	<?=Utils::loadSegment(dirname(__FILE__)."/segments/_s_dictionary_category_.php")?>
	<p class="meta"><strong><?=$count?></strong> words in <em><?=$category==""?"ALL":$category?></em></p>
	<div class="vspacing-short"></div>
	<?php if($terms) {?>
	<table class="terms">
		<?php foreach($terms as $term) {?>
		<tr>
			<th>
				<em class="term"><?=$term['term']?></em>
				<?php if($isEditor) { ?>
				<a href="#" title="Delete" class="circle-remove" onclick="dictionary.delete_term(this, <?=$term['serial']?>);return false;">delete</a>
				<?php } ?>
			</th>
			<td>
				<ol>
				<?php foreach($term['definition'] as $definition) {?>
					<li serial="<?=$definition['serial']?>">
						<em class="definition"><?=nl2br($definition['definition'])?></em>
						<br />
						<ul class="piece-little">
						<?php $comefroms = explode(',', $definition['comefrom']); foreach($comefroms as $comefrom) { ?>
							<?php if($isEditor) { ?>
								<?php if($comefrom == $comefroms[0]) { ?>
								<li serial="<?=$comefrom?>"><a class="button source-single" href="<?=get_source_url($comefrom)?>"><?=$source_all_abbrs[$comefrom]?></a></li>
								<?php } else {?>
								<li serial="<?=$comefrom?>"><a class="button source" href="<?=get_source_url($comefrom)?>"><?=$source_all_abbrs[$comefrom]?></a><a class="button split" title="Split" onclick="dictionary.split(this)">&times;</a></li>
								<?php }?>
							<?php } else { ?>
								<li serial="<?=$comefrom?>"><a class="button source-single" href="<?=get_source_url($comefrom)?>"><?=$source_all_abbrs[$comefrom]?></a></li>
							<?php } ?>
						<?php } ?>
						</ul>
						<div class="clear"></div>
						<?php if($isEditor && $definition['conflict_definition']) {?>
							<div class="vspacing-short"></div>
							<?php foreach($definition['conflict_definition'] as $conflict) { ?>
							<?php if($conflict == "") { ?> 
							<p class="conflict"><span>(Dropped from <?=$conflict['comefrom']?>) - </span>
							<?php } else { ?>
							<p class="conflict"><span>(Changed from <?=$conflict['comefrom']?>) - </span><?=$conflict['definition']?>
							<?php }?>
							<a href="#" class="cancel" title="Discard" onclick="dictionary.handle_conflict(this, <?=$conflict['serial']?>, 'discard')">Discard</a>
							<a href="#" class="ok" title="Adopt" onclick="dictionary.handle_conflict(this, <?=$conflict['serial']?>, 'adopt')">Adopt</a></p>
						<?php }} ?>
					</li>
				<?php }?>
				</ol>
				<?php if($isEditor) { ?>
				<a href="#" title="Sort Definitions" class="circle-sort" onclick="dictionary.sort_start(this);return false;">Sort</a>
				<a href="#" title="Merge Definitions" class="circle-merge" onclick="dictionary.merge_start(this, <?=$term['serial']?>);return false;">Merge</a>
				<?php }?>
			</td>
		</tr>
		<?php }?>
	</table>
	<?php }?>
	<?=$pageNav?>
</div>
<?= $footer['html']?>
